/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.common.query;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * 长整形类型的范围查询条件
 *
 * @author 挺好的 2023年05月30日 18:46
 */
@Data
@EqualsAndHashCode (callSuper = false)
@SuperBuilder
@NoArgsConstructor
public class LongBetween extends BaseBetween <Long, Long> {

    /**
     * 创建数字范围的查询条件
     *
     * @param lowerBound
     *         左边的值
     * @param upperBound
     *         右边的值
     *
     * @return
     */
    public static LongBetween of (Long lowerBound, Long upperBound) {
        return LongBetween.builder().lowerBound(lowerBound).upperBound(upperBound).build();
    }

    /**
     * 是否有效，如果无效，将不添加到搜索条件中。
     * 当 lowerBound == null || upperBound == null ，返回false， 当 lowerBound <= upperBound，返回true，否则返回false
     *
     * @return 是否有效
     */
    @Override
    public boolean isValid () {

        boolean isValid = super.isValid();

        if (!isValid) {
            return false;
        }

        Long lowerBound = super.getLowerBound();
        Long upperBound = super.getUpperBound();

        return lowerBound <= upperBound;
    }

}
